package jarVersion;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class JDKVersion {
	  private static final int JAVA_CLASS_MAGIC = 0xCAFEBABE;
	  
	  public static void main(String[] args){        
	    try {               
	     DataInputStream dis = new DataInputStream(new FileInputStream("C:\\LJ\\test\\BusiLegalVehicle.class"));
	     int magic = dis.readInt();
	     if(magic == JAVA_CLASS_MAGIC){
	      int minorVersion = dis.readUnsignedShort();
	      int majorVersion = dis.readUnsignedShort();
	      
//	      Java 1.2 uses major version 46
//	      Java 1.3 uses major version 47
//	      Java 1.4 uses major version 48
//	      Java 5 uses major version 49
//	      Java 6 uses major version 50
//	      Java 7 uses major version 51  
	      
	      System.out.println("ClassVersionTest.main() " + majorVersion + "." + minorVersion);
	      }
	      }catch (FileNotFoundException e){
	       // TODO Auto-generated catch block
	        e.printStackTrace();
	       } catch (IOException e){
	       // TODO Auto-generated catch block
	        e.printStackTrace();
	       }
	   }
	}